home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / csim / source.lha / source / Threads / GnuThreads / sun4.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-14  |  1.6 KB  |  55 lines

  1. /*
  2.  * init.c -- lightweight process initialisation for sun4.
  3.  * Copyright (C) 1991 Stephen Crane.
  4.  *
  5.  * This is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 1, or (at your option)
  8.  * any later version.
  9.  *
  10.  * This software is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * see the file COPYING.  If not, write to
  17.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  * author: Stephen Crane, (jsc@doc.ic.ac.uk), Department of Computing,
  20.  * Imperial College of Science, Technology and Medicine, 180 Queen's
  21.  * Gate, London SW7 2BZ, England.
  22.  */
  23.  
  24. #include "gnulwp.h"
  25.  
  26. #include <setjmp.h>
  27.  
  28. /*
  29.  * initp -- initialise a new process's context.  Stack pointer in
  30.  * newp->context[0], because it's easier for the SPARC code.
  31.  */
  32.  
  33. void initp (struct pcb *newp)
  34. {
  35.     static jmp_buf *cpp;
  36.     extern struct pcb *currp;
  37.     
  38.     /* preserve cpp for new context */
  39.     cpp = &newp->context;
  40.     if (!savep (currp->context)) {
  41.         /* create new context */        
  42.         /* flush registers */
  43.         asm ("ta    0x03");
  44.         /* %o0 <- newp */
  45.         asm ("ld    [%fp+0x44], %o0");
  46.         /* %o1 <- newp->context[0] */
  47.         asm ("ld    [%o0], %o1");
  48.         /* create min frame on new stack */
  49.         asm ("save    %o1,-96, %sp");
  50.         if (!savep (*cpp))
  51.             restorep (currp->context);
  52.         wrapp ();
  53.     }
  54. }
  55.